package com.xunji.user.entity;


import com.baomidou.mybatisplus.annotation.TableName;
import com.xunji.user.util.UUIDUtil;
import com.xunji.user.vo.req.UserAddRequest;
import com.xunji.user.vo.req.UserUpdateRequest;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

@TableName(value = "t_lp_user")
@Data
public class User extends BaseEntity {

    private String id;

    private String name;

    private String loginName;

    private String password;

    private Integer gender;

    private Integer departmentId;

    private String phoneNumber;

    //private Integer withLoginName;

    private Integer status;

    private String image;

    // 是否上传人脸 0未上传 1已上传
    //private Integer withLoginImage;


    public static User getInstance(UserAddRequest request) {
        User user = new User();
        user.setId(UUIDUtil.getUUID());
        user.setName(request.getName());
        user.setLoginName(request.getLoginName());
        user.setGender(request.getGender());
        user.setDepartmentId(request.getDepartmentId());
        user.setPhoneNumber(request.getPhoneNumber());
        //user.setWithLoginName(request.getWithLoginName());
        user.setImage(request.getImageName());
        user.setStatus(1);
        user.setCreatedTime(LocalDateTime.now());
        return user;
    }


    public static void getInstance(UserUpdateRequest request, User user) {
        user.setGender(request.getGender());
        user.setPhoneNumber(request.getPhoneNumber());
        user.setName(request.getName());
        if (StringUtils.hasText(request.getLoginName()) && !StringUtils.hasText(user.getLoginName())) {
            user.setLoginName(request.getLoginName());
        }
        user.setDepartmentId(request.getDepartmentId());
        //user.setWithLoginName(request.getWithLoginName());
        user.setImage(request.getImageName());
        user.setUpdatedTime(LocalDateTime.now());
    }
}
